package com.hut.blog.mapper;

import com.hut.blog.model.BlogInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BlogMapper {
    /**
     * 返回博客列表
     * @return
     */
    @Select("select id, title, content, user_id, delete_flag, create_time, update_time from blog where " +
            "delete_flag =0")
    List<BlogInfo> getBlogList();

    /**
     * 根据blogId返回blog信息
     * @param id
     * @return
     */
    @Select("select id, title, content, user_id, delete_flag, create_time, update_time from blog where " +
            "delete_flag =0 and id = #{id}")
    BlogInfo getBlogInfoById(Integer id);

    /**
     * 更新blog
     * @param blogInfo
     * @return
     */
    Integer updateBlogInfo(BlogInfo blogInfo);

    /**
     * 发布blog
     * @param blogInfo
     * @return
     */
    @Insert("insert into blog(title, content, user_id) values (#{title}, #{content}, #{userId})")
    Integer insertBlogInfo(BlogInfo blogInfo);
}
